﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.WindowsAzure.StorageClient;
using CashFlow.Entities;
using AutoMapper;

namespace CashFlow.AzureRepository
{
	public class AzureAppIdentity : TableServiceEntity
	{

		#region Field and properties
		/// <summary>
		/// Gets or sets the name.
		/// </summary>
		/// <value>The name.</value>
		public string Name
		{
			get;
			set;
		}

		/// <summary>
		/// Gets or sets the friendly name.
		/// </summary>
		/// <value>The friendly name.</value>
		public string FriendlyName
		{
			get;
			set;
		}

		/// <summary>
		/// Gets or sets the provider.
		/// </summary>
		/// <value>The provider.</value>
		public string Provider
		{
			get;
			set;
		}

		/// <summary>
		/// Gets or sets the tenant id.
		/// </summary>
		/// <value>The tenant id.</value>
		public string TenantId
		{
			get;
			set;
		} 
		#endregion

		#region Constructors
		/// <summary>
		/// Initializes a new instance of the <see cref="T:AppIdentityAzure"/> class.
		/// </summary>
		static AzureAppIdentity()
		{
			Mapper.CreateMap<AppIdentity, AzureAppIdentity>().
				ForMember(dest => dest.PartitionKey, opt => opt.MapFrom(src => src.Provider)).
				ForMember(dest => dest.RowKey, opt => opt.MapFrom(src => src.EncodedIdentifier));

			Mapper.CreateMap<AzureAppIdentity, AppIdentity>();

		}
		#endregion

		#region Mappers
		public static explicit operator AzureAppIdentity(AppIdentity entity)
		{
			var model = Mapper.Map<AppIdentity, AzureAppIdentity>(entity);
			return model;
		}

		public static explicit operator AppIdentity(AzureAppIdentity model)
		{
			var entity = Mapper.Map<AzureAppIdentity, AppIdentity>(model);
			return entity;
		}
		#endregion

	}
}
